package org.example.framework;

import cn.hutool.core.util.RandomUtil;
import cn.lingyangwl.framework.tool.core.exception.BizException;

import java.util.List;

/**
 * @author shenguangyang
 */
public class LoadBalance {
    public static Invoker random(List<Invoker> invokers) {
        if (invokers.isEmpty()) {
            throw new BizException("serverUrls isEmpty");
        }
        if (invokers.size() == 1) {
            return invokers.get(0);
        }
        int index = RandomUtil.randomInt(0, invokers.size() - 1);
        return invokers.get(index);
    }
}
